package com.ysx.server.controller;

import com.ysx.server.pojo.dto.CommentAddDTO;
import com.ysx.server.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/comment")
@Slf4j
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 创建评论
     * @param commentAddDTO
     * @return
     */
    @PostMapping("/addComment")
    @CacheEvict(cacheNames = {"goodsCache_new","goodsCache_all","goodsCache"},allEntries=true)
    public boolean createComment(@RequestBody CommentAddDTO commentAddDTO){
        log.info("创建评论{}",commentAddDTO);
        if(commentAddDTO==null)
            return false;
        return commentService.addComment(commentAddDTO);
    }
}
